home *** CD-ROM | disk | FTP | other *** search
- /* ------------------------------------------------------------ */
- /*
- HTTrack Website Copier, Offline Browser for Windows and Unix
- Copyright (C) Xavier Roche and other contributors
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-
- Important notes:
-
- - We hereby ask people using this source NOT to use it in purpose of grabbing
- emails addresses, or collecting any other private information on persons.
- This would disgrace our work, and spoil the many hours we spent on it.
-
-
- Please visit our Website: http://www.httrack.com
- */
-
-
- /* ------------------------------------------------------------ */
- /* File: Subroutines .h */
- /* Author: Xavier Roche */
- /* ------------------------------------------------------------ */
-
- // Fichier librairie .h
-
- #ifndef HTS_DEFH
- #define HTS_DEFH
-
- /* dΘfinitions globales */
- #include "htsglobal.h"
-
- /* basic net definitions */
- #include "htsbasenet.h"
-
- /* cookies et auth */
- #include "htsbauth.h"
-
- // Attention, dΘfinition existante Θgalement dans le shell
- // (α modifier avec celle-ci)
- #define POSTTOK "?>post"
-
- #include <stdio.h>
-
- /*
- #if HTS_WIN
- #include <winsock.h>
- typedef SOCKET T_SOC;
- typedef struct hostent FAR t_hostent;
- #else
- typedef int T_SOC;
- typedef struct hostent t_hostent;
- #endif
- */
-
- /*
- #include <ctype.h>
- #if HTS_WIN
- #include <winsock.h>
- typedef SOCKET T_SOC;
- // pour read
- #include <io.h>
- // pour FindFirstFile
- #include <winbase.h>
- #else
- typedef int T_SOC;
- #define INVALID_SOCKET -1
- #include <netdb.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <sys/time.h>
- #include <sys/ioctl.h>
- // gethostname & co0
- #include <unistd.h>
- // inet_addr
- #include <arpa/inet.h>
- // pas la peine normalement..
- #if HTS_PLATFORM!=3
- #include <sys/filio.h>
- #else
- #ifndef HTS_DO_NOT_REDEFINE_in_addr_t
- typedef unsigned long in_addr_t;
- #endif
- #endif
-
- #ifndef min
- #define min(a,b) ((a)>(b)?(b):(a))
- #define max(a,b) ((a)>(b)?(a):(b))
- #endif
- #define Sleep(a) { if (((a)*1000)%1000000) usleep(((a)*1000)%1000000); if (((a)*1000)/1000000) sleep(((a)*1000)/1000000); }
- #endif
- */
-
- /*
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- #include <fcntl.h>
- // pour utimbuf
- #if HTS_PLATFORM!=3
- #include <utime.h>
- #else
- #include <utime.h>
- #endif
- */
-
- /*
- // teste ΘgalitΘ de 2 chars, case insensitive
- #define hichar(a) ((((a)>='a') && ((a)<='z')) ? ((a)-('a'-'A')) : (a))
- #define streql(a,b) (hichar(a)==hichar(b))
-
- // caractΦre maj
- #define isUpperLetter(a) ( ((a) >= 'A') && ((a) <= 'Z') )
- */
- /*
- #if HTS_PLATFORM!=3
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if HTS_PLATFORM!=2
- #if HTS_PLATFORM!=1
- int open (const char *, int, ...);
- #endif
- //int read (int,const char*,int);
- //int write (int,char*,int);
- #endif
- #if HTS_PLATFORM!=1
- int close (int);
- void* calloc (size_t,size_t);
- void* malloc (size_t);
- void* realloc (void*,size_t);
- void free (void*);
- #endif
- #if HTS_WIN==0
- void bzero (char*,unsigned int);
- void bcopy (const char*,char*,unsigned int);
- //int strcasecmp(const char*,const char*);
- #endif
- //int strlen (const char *);
- #if HTS_WIN
- //int mkdir (const char*);
- #else
- int mkdir (const char*,mode_t);
- int isdigit (char);
- int isalpha (char);
- int isalnum (char);
- #endif
- #ifdef __cplusplus
- }
- #endif
- #endif
- */
-
- /*
- // conversion Θventuelle / vers antislash
- #if HTS_WIN
- char* antislash(char* s);
- #else
- #define antislash(A) (A)
- #endif
- */
-
- /*
- #if HTS_WIN
- #define bzero(a,b) memset(a,0,b)
- #define bcopy(a,b,c) memcpy(b,a,c)
- #endif
-
- // tracer malloc()
- #if HTS_TRACE_MALLOC
- #define malloct(A) hts_malloc(A,0)
- #define calloct(A,B) hts_malloc(A,B)
- #define freet(A) hts_free(A)
- #define realloct(A,B) hts_realloc(A,B)
- void hts_freeall();
- void* hts_malloc (size_t,size_t);
- void hts_free (void*);
- void* hts_realloc (void*,size_t);
- #else
- #define malloct(A) malloc(A)
- #define calloct(A,B) calloc(A,B)
- #define freet(A) free(A)
- #define realloct(A,B) realloc(A,B)
- #endif
- */
-
- #include "htsopt.h"
-
- // structure pour paramΦtres supplΘmentaires lors de la requΩte
- typedef struct {
- short int user_agent_send; // user agent (ex: httrack/1.0 [sun])
- short int http11; // l'en tΩte peut (doit) Ωtre signΘ HTTP/1.1 et non HTTP/1.0
- char user_agent[64];
- char lang_iso[64];
- t_proxy proxy; // proxy
- } htsrequest;
-
-
- // structure pour retour d'une connexion/prise d'en tΩte
- typedef struct {
- int statuscode; // status-code, -1=erreur, 200=OK,201=..etc (cf RFC1945)
- short int notmodified; // page ou fichier NON modifiΘ (transfΘrΘ)
- short int is_write; // sortie sur disque (out) ou en mΘmoire (adr)
- short int is_chunk; // mode chunk
- char* adr; // adresse du bloc de mΘmoire, NULL=vide
- FILE* out; // Θcriture directe sur disque (si is_write=1)
- LLint size; // taille fichier
- char msg[80]; // message Θventuel si Θchec ("\0"=non prΘcisΘ)
- char contenttype[64]; // content-type ("text/html" par exemple)
- char* location; // on copie dedans Θventuellement la vΘritable 'location'
- LLint totalsize; // taille totale α tΘlΘcharger (-1=inconnue)
- short int is_file; // ce n'est pas une socket mais un descripteur de fichier si 1
- T_SOC soc; // ID socket
- FILE* fp; // fichier pour file://
- char lastmodified[64]; // Last-Modified
- char etag[64]; // Etag
- char cdispo[256]; // Content-Disposition coupΘ
- /* */
- htsrequest req; // paramΦtres pour la requΩte
- /*char digest[32+2]; // digest md5 gΘnΘrΘ par le moteur ("" si non gΘnΘrΘ)*/
- } htsblk;
-
-
- /* ANCIENNE STURCTURE pour cache 1.0 */
- typedef struct {
- int statuscode; // ANCIENNE STURCTURE - status-code, -1=erreur, 200=OK,201=..etc (cf RFC1945)
- int notmodified; // ANCIENNE STURCTURE - page ou fichier NON modifiΘ (transfΘrΘ)
- int is_write; // ANCIENNE STURCTURE - sortie sur disque (out) ou en mΘmoire (adr)
- char* adr; // ANCIENNE STURCTURE - adresse du bloc de mΘmoire, NULL=vide
- FILE* out; // ANCIENNE STURCTURE - Θcriture directe sur disque (si is_write=1)
- int size; // ANCIENNE STURCTURE - taille fichier
- char msg[80]; // ANCIENNE STURCTURE - message Θventuel si Θchec ("\0"=non prΘcisΘ)
- char contenttype[64]; // ANCIENNE STURCTURE - content-type ("text/html" par exemple)
- char* location; // ANCIENNE STURCTURE - on copie dedans Θventuellement la vΘritable 'location'
- int totalsize; // ANCIENNE STURCTURE - taille totale α tΘlΘcharger (-1=inconnue)
- int is_file; // ANCIENNE STURCTURE - ce n'est pas une socket mais un descripteur de fichier si 1
- T_SOC soc; // ANCIENNE STURCTURE - ID socket
- FILE* fp; // ANCIENNE STURCTURE - fichier pour file://
- t_proxy proxy; // ANCIENNE STURCTURE - proxy
- int user_agent_send; // ANCIENNE STURCTURE - user agent (ex: httrack/1.0 [sun])
- char user_agent[64];
- int http11; // ANCIENNE STURCTURE - l'en tΩte doit Ωtre signΘ HTTP/1.1 et non HTTP/1.0
- } OLD_htsblk;
- /* fin ANCIENNE STURCTURE pour cache 1.0 */
-
- // cache pour le dns, pour Θviterd de faire des gethostbyname sans arrΩt
- typedef struct t_dnscache {
- char iadr[1024];
- char host_addr[16]; // 4 octets normalement ()
- int host_length; // 4 normalement - ==0 alors en cours de rΘsolution
- // ==-1 alors erreur (host n'Θxiste pas)
- struct t_dnscache* n;
- } t_dnscache;
-
-
- typedef struct {
- LLint HTS_TOTAL_RECV; // flux entrant reτu
- LLint stat_bytes; // octets Θcrits sur disque
- int HTS_TOTAL_RECV_STATE; // status: 0 tout va bien 1: ralentir un peu 2: ralentir 3: beaucoup
- double stat_timestart; // dΘpart
- double imstat_timestart; // dΘpart pour calcul instantannΘ
- LLint istat_bytes; // calcul pour instantannΘ
- int stat_files; // nombre de fichiers Θcrits
- int stat_updated_files; // nombre de fichiers mis α jour
- //
- LLint rate;
- } hts_stat_struct;
-
-
-
- /*
- #ifdef __cplusplus
- extern "C" {
- #endif
- */
-
- // fonctions unix/winsock
- int hts_read(htsblk* r,char* buff,int size);
- void HTS_TOTAL_RECV_CHECK(int var);
-
- // fonctions principales
- int http_fopen(char* adr,char* fil,htsblk* retour);
- int http_xfopen(int mode,int treat,int waitconnect,char* xsend,char* adr,char* fil,htsblk* retour);
- int http_sendhead(t_cookie* cookie,int mode,char* xsend,char* adr,char* fil,char* referer_adr,char* referer_fil,htsblk* retour);
- htsblk httpget(char* url);
- //int newhttp(char* iadr,char* err=NULL);
- int newhttp(char* iadr,htsblk* retour,int port,int waitconnect);
- HTS_INLINE void deletehttp(htsblk* r);
- HTS_INLINE void deletesoc(T_SOC soc);
- htsblk http_location(char* adr,char* fil,char* loc);
- htsblk http_test(char* adr,char* fil,char* loc);
- void http_fread(T_SOC soc,htsblk* retour);
- LLint http_fread1(htsblk* r);
- void treathead(t_cookie* cookie,char* adr,char* fil,htsblk* retour,char* rcvd);
- void treatfirstline(htsblk* retour,char* rcvd);
- void infostatuscode(char* msg,int statuscode);
-
- // sous-fonctions
- htsblk xhttpget(char* adr,char* fil);
- htsblk http_gethead(char* adr,char* fil);
- LLint http_xfread1(htsblk* r,int bufl);
- HTS_INLINE t_hostent* hts_gethostbyname(char* iadr);
- t_hostent* _hts_ghbn(t_dnscache* cache,char* iadr,t_hostent* retour);
- int ftp_available(void);
- #if HTS_DNSCACHE
- int hts_dnstest(char* _iadr);
- t_dnscache* _hts_cache(void);
- int _hts_lockdns(int i);
- #endif
-
- // outils divers
- HTS_INLINE double time_local(void);
- HTS_INLINE double mtime_local(void);
- void sec2str(char *s,double t);
- void qsec2str(char *st,double t);
- void time_gmt_rfc822(char* s);
- void time_local_rfc822(char* s);
- struct tm* convert_time_rfc822(char* s);
- int set_filetime(char* file,struct tm* tm_time);
- int set_filetime_rfc822(char* file,char* date);
- HTS_INLINE void time_rfc822(char* s,struct tm * A);
- HTS_INLINE void time_rfc822_local(char* s,struct tm * A);
- char* int2bytes(LLint n);
- char* int2bytessec(long int n);
- char** int2bytes2(LLint n);
- HTS_INLINE int sendc(T_SOC soc,char* s);
- void finput(int fd,char* s,int max);
- int binput(char* buff,char* s,int max);
- void linput(FILE* fp,char* s,int max);
- void linput_trim(FILE* fp,char* s,int max);
- void linput_cpp(FILE* fp,char* s,int max);
- void rawlinput(FILE* fp,char* s,int max);
- int strfield(const char* f,const char* s);
- #define strfield2(f,s) ( (strlen(f)!=strlen(s)) ? 0 : (strfield(f,s)) )
- char* strstrcase(char *s,char *o);
- int ident_url(char* url,char* adr,char* fil);
- void fil_simplifie(char* f);
- int ishtml(char* urlfil);
- int ishtml_ext(char* a);
- int ishttperror(int err);
- void guess_httptype(char *s,char *fil);
- void get_httptype(char *s,char *fil,int flag);
- void give_mimext(char *s,char *st);
- int is_knowntype(char *fil);
- char* get_ext(char *fil);
- int may_unknown(char* st);
- char* jump_identification(char*);
- HTS_INLINE char* jump_protocol(char* source);
- void code64(char* a,char* b);
- void unescape_amp(char* s);
- void escape_spc_url(char* s);
- void escape_in_url(char* s);
- void escape_check_url(char* s);
- void x_escape_http(char* s,int mode);
- HTS_INLINE int ehexh(char c);
- char* unescape_http(char* s);
- char* antislash_unescaped(char* s);
- int ehex(char* s);
- char* concat(const char* a,const char* b);
- #define copychar(a) concat((a),NULL)
- #if HTS_DOSNAME
- char* fconcat(char* a,char* b);
- char* fconv(char* a);
- #else
- #define fconv(a) (a)
- #define fconcat(a,b) concat(a,b)
- #endif
- char* fslash(char* a);
- char* __fslash(char* a);
-
- char* convtolower(char* a);
- char* concat(const char* a,const char* b);
- void hts_lowcase(char* s);
- void hts_replace(char *s,char from,char to);
-
- /* Spaces: CR,LF,TAB,FF */
- #define is_space(c) ( ((c)==' ') || ((c)=='\"') || ((c)==10) || ((c)==13) || ((c)==9) || ((c)==12) || ((c)=='\'') )
- #define is_realspace(c) ( ((c)==' ') || ((c)==10) || ((c)==13) || ((c)==9) || ((c)==12) )
- //HTS_INLINE int is_space(char);
- //HTS_INLINE int is_realspace(char);
-
- void cut_path(char* fullpath,char* path,char* pname);
- int fexist(char* s);
- /*LLint fsize(char* s); */
- int fpsize(FILE* fp);
- int fsize(char* s);
-
- // Threads
- #if USE_PTHREAD
- typedef void* ( *beginthread_type )( void * );
- unsigned long _beginthread( beginthread_type start_address, unsigned stack_size, void *arglist );
- #endif
-
- /*
- #ifdef __cplusplus
- }
- #endif
- */
-
-
-
- /* variables globales */
- //extern LLint HTS_TOTAL_RECV; // flux entrant reτu
- //extern int HTS_TOTAL_RECV_STATE; // status: 0 tout va bien 1: ralentir un peu 2: ralentir 3: beaucoup
- extern hts_stat_struct HTS_STAT;
- extern int _DEBUG_HEAD;
- extern FILE* ioinfo;
-
- /* constantes */
- extern const char hts_mime_keep[][32];
- extern const char hts_mime[][2][32];
- extern const char hts_detect[][32];
- extern const char hts_detectURL[][32];
- extern const char hts_detectandleave[][32];
- extern const char hts_detect_js[][32];
-
- #endif
-
-
-